home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / allswags.zip / CRT.SWG < prev    next >
Text File  |  1993-05-29  |  13KB  |  1 lines

  1. SWAGOLX.EXE (c) 1993 GDSOFT  ALL RIGHTS RESERVED 00009         CRT ROUTINES                                                      1      05-28-9313:36ALL                      SWAG SUPPORT TEAM        XY Cursor Position in ASMIMPORT              15          {π> If anyone is interested in the BAsm GotoXY/WhereX/WhereY routinesπ> I'll be happy to post them.   They use standard BIOS routines, andππI simply followed an Interrupt listing I had to create these Functions.ππNote the DEC commands in GotoXY, and the INC command in Each WHERE* Function.πThese are there to make the Procedures/Functions Compatible With the TP Crtπroutines, which are 1-based.  (ie: 1,1 in TP.Crt is upper left hand corner).πThe BIOS routines need to be given 0,0 For the same coordinates.   If you don'tπwant to remain Compatible With Turbo's GotoXY and WHERE* Functions, delete themπout and keep your code Zero-based For X/Y screen coords.π}ππProcedure GotoXY(X,Y : Byte); Assembler; Asmπ  MOV DH, Y    { DH = Row (Y) }π  MOV DL, X    { DL = Column (X) }π  DEC DH       { Adjust For Zero-based Bios routines }π  DEC DL       { Turbo Crt.GotoXY is 1-based }π  MOV BH,0     { Display page 0 }π  MOV AH,2     { Call For SET CURSOR POSITION }π  INT 10hπend;ππFunction  WhereX : Byte;  Assembler;πAsmπ  MOV     AH,3      {Ask For current cursor position}π  MOV     BH,0      { On page 0 }π  INT     10h       { Return inFormation in DX }π  INC     DL        { Bios Assumes Zero-based. Crt.WhereX Uses 1 based }π  MOV     AL, DL    { Return X position in AL For use in Byte Result }πend;ππFunction WhereY : Byte; Assembler;πAsmπ  MOV     AH,3     {Ask For current cursor position}π  MOV     BH,0     { On page 0 }π  INT     10h      { Return inFormation in DX }π  INC     DH       { Bios Assumes Zero-based. Crt.WhereY Uses 1 based }π  MOV     AL, DH   { Return Y position in AL For use in Byte Result }πend;ππ{πNote that the WhereX and WhereY Function call the exact same Bios function.π}π                                                                                       2      05-28-9313:36ALL                      SWAG SUPPORT TEAM        Set EGA/VGA Blink Bit    IMPORT              13          π  Hi, Rolfi:ππRM>Anybody know and easy way to do DarkGrey for a bkgrnd???ππ  ...You have to turn off the "blink-bit", if possible. This isπ  only available for CGA and EGA/VGA color text modes.ππ  (***** Turn the "blink-bit" on/off to allow 16 different background *)π  (*     colors. (CGA ONLY!)                                          *)π  (*                                                                  *)π  procedure SetBlinkCGA({input } TurnOn : boolean);π  beginπ    if TurnOn thenπ      beginπ        mem[$0040:$0065] := (mem[$0040:$0065] AND (NOT $20));π        port[$3D8] := $29π      endπ    elseπ      beginπ        mem[$0040:$0065] := (mem[$0040:$0065] OR $20);π        port[$3D8] := $09π      endπ  end;        (* SetBlinkCGA.                                         *)πππ  (***** Turn the "blink-bit" on/off to allow 16 different background *)π  (*     colors. (EGA or VGA ONLY!)                                   *)π  (*                                                                  *)π  procedure SetBlinkEGAVGA({input } TurnOn : boolean);π  beginπ    asmπ      mov ax, 1003hπ      mov bl, TurnOnπ      int 10hπ    endπ  end;        (* SetBlinkEGAVGA.                                      *)ππ                               - Guyπ---π ■ DeLuxe²/386 1.25 #5060 ■π * Rose Media, Toronto, Canada : 416-733-2285π * PostLink(tm) v1.04  ROSE (#1047) : RelayNet(tm)ππ                                                                                                                                                       3      05-28-9313:36ALL                      SWAG SUPPORT TEAM        Clear CRT Screen FAST    IMPORT              3           {π>Does anyone know how to clear the screen Really fast ?πWell, here is some Asm code but I haven't tested it. It should work:π}ππProcedure FastClrScr; Assembler;πAsmπ  MOV AH,0Fhπ  INT 10hπ  MOV AH,0π  INT 10hπend;ππbeginπ  FastClrScr;πend.               4      05-28-9313:36ALL                      SWAG SUPPORT TEAM        Clear VGA Screen         IMPORT              6           {π>> Does anyone know how to clear the screen Really fast ?π>> I'm working in VGA-mode With a resolution of 320*200*256π> You could try a block rewriting of the palettes, but that would probablyπ> take even longer, since it is usually an interrupt instruction.ππWell, use the standard pascal routine called FillChar. ;-)π}ππFillChar(Mem[$A000:$0000],320*200,0);ππ{ You can double speed by using 16 bit wide data transfer: }ππProcedure FillChar16(Var X;Count : Word;Value : Byte); Assembler;πAsmπ  les   di,Xπ  mov   cd,Countπ  shr   cx,1π  mov   al,Valueπ  mov   ah,alπ  rep   stoswπ  test  Count,1π  jz    @endπ  stosbπ@end:πend;ππ        5      05-28-9313:36ALL                      SWAG SUPPORT TEAM        CPU Delay                IMPORT              4           {π> does anyone have an accurate BAsm Delay routine that isπ> compatible With the one in the Crt Unit? please post it...π}ππProcedure Delay(ms : Word); Assembler;πAsm {machine independent Delay Function}π  mov ax, 1000;π  mul ms;π  mov cx, dx;π  mov dx, ax;π  mov ah, $86;π  int $15;πend;π                                                                                               6      05-28-9313:36ALL                      SWAG SUPPORT TEAM        Reading Keys             IMPORT              5           {π> Could someone please post an Asm equivalent ofπ> Repeat Until KeyPressed;ππWell, here it is using the Dos Unit instead of the Crt....  :)π}πUses Dos;πVarπ  r : Registers;ππFunction _ReadKey : Char;πbeginπ  r.ax := $0700;π  intr($21, r);π  _ReadKey := chr(r.al);πend;ππFunction _KeyPressed : Boolean;πbeginπ  r.ax := $0b00;π  intr($21,r);π  if r.al = 255 thenπ    _KeyPressed := Trueπ  elseπ    _KeyPressed := False;πend;πbeginπ  Repeat Until _keypressed;πend.                                                 7      05-28-9313:36ALL                      SWAG SUPPORT TEAM        Check KEYPRESS           IMPORT              15          {πTo the person that posted the message about using KeyPressed or anyoneπelse interested. Below is a Function that I have used to read keyboard inputπthat is similiar to KeyPressed.  It does a KeyPressed and ReadKey all in oneπstatement.  If you are familiar With BASIC this InKey Function is similiarπto the one in BASIC in that is doesn't sit and wait For input.  The KeyEnhπFunction just returns True/False depending on whether or not it detectedπan Enhanced keyboard. SHIFT, CTRL, and ALT are global Boolean Variablesπwhich value reflect the state of these keys involved in the the keypress.π}ππUsesπ  Dos;ππFunction KeyEnh:  Boolean;πVarπ  Enh:  Byte Absolute $0040:$0096;ππbeginπ  KeyEnh := False;π  if (Enh and $10) = $10 thenπ    KeyEnh := True;πend;ππFunction InKey(Var SCAN, ASCII:  Byte): Boolean;πVarπ  i     :  Integer;π  Shift,π  Ctrl,π  Alt   : Boolean;π  Temp,π  Flag1 : Byte;π  HEXCH,π  HEXRD,π  HEXFL : Byte;π  reg   : Registers;ππbeginπ  if KeyEnh thenπ  beginπ    HEXCH := $11;π    HEXRD := $10;π    HEXFL := $12;π  endπ  elseπ  beginπ    HEXCH := $01;π    HEXRD := $00;π    HEXFL := $02;π  end;ππ  reg.ah := HEXCH;π  Intr($16, reg);π  i := reg.flags and FZero;ππ  reg.ah := HEXFL;π  Intr($16, reg);π  Flag1 := Reg.al;π  Temp  := Flag1 and $03;ππ  if Temp = 0 thenπ    SHIFT := Falseπ  ELSEπ    SHIFT := True;ππ  Temp  := Flag1 and $04;π  if Temp = 0 thenπ    CTRL := Falseπ  ELSEπ    CTRL := True;ππ  Temp  := Flag1 and $08;π  if Temp = 0 Thenπ    ALT  := Falseπ  ELSEπ    ALT  := True;ππ  if i = 0 thenπ  beginπ    reg.ah := HEXRD;π    Intr($16, reg);π    scan  := reg.ah;π    ascii := reg.al;π    InKey := True;π  endπ  elseπ    InKey := False;πend;πππVarπ  Hi, Hi2 : Byte;ππbeginπ  Repeat Until InKey(Hi,Hi2);π  Writeln(Hi);π  Writeln(Hi2);πend.                       8      05-28-9313:36ALL                      SWAG SUPPORT TEAM        Readkey and KEYPRESS     IMPORT              7           {πCrt Unit, but I don't want to use the Crt.  Could some one showπme a routine For Pause, or Delay With a Time Factor?ππ  ...I can supply you With KeyPressed and ReadKey routines Forπ  TP6 or TP7, which could be used to create a Pause routine.π  The Delay is a bit harder, I've got a routine I wrote lastπ  year For this, but I'm still not happy With it's accuracy.π}ππ{ Read a key-press. }πFunction ReadKeyChar : {output} Char; Assembler;πAsmπ  mov ah, 00hπ  int 16hπend; { ReadKeyChar. }ππ{ Function to indicate if a key is in the keyboard buffer. }πFunction KeyPressed : {output} Boolean; Assembler;πAsmπ  mov ah, 01hπ  int 16hπ  mov ax, 00hπ  jz #1π  inc axπ  @1:πend; { KeyPressed. }π                                                                               9      05-28-9313:36ALL                      SWAG SUPPORT TEAM        Small CRT Replacement    IMPORT              30          Unit sCrt;ππ{ππ  by Trevor J Carlsenπ     PO Box 568π     Port Hedlandπ     Western Australia 6721π     Phone -π       Voice: 61 91 732026π       Data : 61 91 732569ππ   This little Unit is intended to replace the Crt Unit in Programs that doπ   not require many of that Units Functions.  As a result the resulting .exeπ   code is much smaller.ππ   Released into the public domain 1989ππ}ππInterfaceππFunction KeyPressed: Boolean;π  { Returns True if there is a keystroke waiting in the key buffer           }ππProcedure ClrScr;π  { Clears the screen and homes the cursor                                   }ππProcedure ClrKey;π  { Flushes the keystroke buffer                                             }ππFunction KeyWord : Word;π    Inline  ($B4/$00/   {mov  ah,0}π             $CD/$16);  {int  16h}π  { Waits For a keypress and returns a Word containing the scancode and      }π  { ascii code For the KeyPressed                                            }ππFunction ExtKey(Var k : Char; Var s : Byte): Boolean;π  { Gets next keystroke from the keystroke buffer. if it was an Extended key }π  { (ie. Function key etc.) returns True and k contains the scan code. if a  }π  { normal key then returns False and k contains the Character and s the scan}π  { code                                                                     }ππFunction ReadKey: Char;π  { Gets next keystroke from the buffer. if Extended key returns #0          }ππFunction NextKey: Char;π  { Flushes the keystroke buffer and then returns the next key as ReadKey    }ππFunction PeekKey: Char;π  { Peeks at the next keypress in the buffer without removing it             }ππProcedure Delay(s : Word);π  { Machine independent Delay loop For s seconds                             }ππProcedure GotoXY(x,y : Byte);π  { Moves the cursor to X, y coordinates                                     }ππ{ -------------------------------------------------------------------------- }ππImplementationππUses Dos;ππVarπ  head : Word    Absolute $0040:$001A;π  tail : Word    Absolute $0040:$001C;π  time : LongInt Absolute $0040:$006C;π  regs : Registers;ππFunction KeyPressed: Boolean;π  beginπ    KeyPressed := (tail <> head);π  end;ππProcedure ClrScr;                                     { 25 line display only }π beginπ   Inline($B4/$06/$B0/$19/$B7/$07/$B5/$00/$B1/$00/$B6/$19/$B2/$4F/π          $CD/$10/$B4/$02/$B7/$00/$B2/$00/$B6/$00/$CD/$10);π end;ππProcedure ClrKey;π  beginπ    head := tail;π  end;πππFunction ExtKey(Var k : Char; Var s : Byte): Boolean;ππ  Varπ    keycode : Word;π    al      : Byte;π    ah      : Byte;ππ  beginπ    ExtKey    := False;π    Repeatπ      keycode := KeyWord;π      al      := lo(keycode);π      ah      := hi(keycode);π      if al = 0 then beginπ        ExtKey := True;π        al     := ah;π      end;π  Until al <> 0;π  k := chr(al);π  s := al;πend;    {ExtKey}ππFunction ReadKey : Char;π  Varπ    Key : Byte;π  beginπ    Key := lo(KeyWord);π    ReadKey := Char(Key);π  end;ππFunction NextKey : Char;π  beginπ    tail := head;π    NextKey := ReadKey;π  end;ππFunction PeekKey : Char;π  beginπ    PeekKey := Char(Mem[$40:head]);π  end;ππProcedure Delay(s : Word);π  Varπ    start    : LongInt;π    finished : Boolean;π  beginπ    start := time;π    Repeatπ      if time < start then    { midnight rollover occurred during the period }π        dec(start,$1800B0);π      finished := (time > (start + s * 18.2));π    Until finished;π  end;ππProcedure GotoXY(x,y : Byte);π  beginπ    With regs do beginπ      ah := $02;π      bh := 0;π      dh := pred(y);π      dl := pred(x);π      intr($10,regs);π    end; { With }π  end;   { GotoXY }ππend.π πππ